package com.lxmes.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lxmes.common.annotation.Log;
import com.lxmes.common.core.controller.BaseController;
import com.lxmes.common.core.domain.AjaxResult;
import com.lxmes.common.enums.BusinessType;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.lxmes.system.domain.MhMessagesBoard;
import com.lxmes.system.service.IMhMessagesBoardService;
import com.lxmes.common.utils.poi.ExcelUtil;
import com.lxmes.common.core.page.TableDataInfo;

/**
 * 在线留言Controller
 * 
 * @author zhangzhiyu
 * @date 2023-06-19
 */
@Api(tags = "在线留言")    
@RestController
@RequestMapping("/system/MhMessagesBoard")
public class MhMessagesBoardController extends BaseController
{
    @Autowired
    private IMhMessagesBoardService mhMessagesBoardService;

    /**
     * 查询在线留言列表
     */
    @ApiOperation("查询在线留言列表")
    @PreAuthorize("@ss.hasPermi('system:MhMessagesBoard:list')")
    @GetMapping("/list")
    public TableDataInfo list(MhMessagesBoard mhMessagesBoard)
    {
        startPage();
        List<MhMessagesBoard> list = mhMessagesBoardService.selectMhMessagesBoardList(mhMessagesBoard);
        return getDataTable(list);
    }

    /**
     * 导出在线留言列表
     */
    @ApiOperation("导出在线留言列表")
    @PreAuthorize("@ss.hasPermi('system:MhMessagesBoard:export')")
    @Log(title = "在线留言", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MhMessagesBoard mhMessagesBoard)
    {
        List<MhMessagesBoard> list = mhMessagesBoardService.selectMhMessagesBoardList(mhMessagesBoard);
        ExcelUtil<MhMessagesBoard> util = new ExcelUtil<MhMessagesBoard>(MhMessagesBoard.class);
        util.exportExcel(response, list, "在线留言数据");
    }

    /**
     * 获取在线留言详细信息
     */
    @ApiOperation("获取在线留言详细信息")
    @PreAuthorize("@ss.hasPermi('system:MhMessagesBoard:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(mhMessagesBoardService.selectMhMessagesBoardById(id));
    }

    /**
     * 新增在线留言
     */
    @ApiOperation("新增在线留言")
    @PreAuthorize("@ss.hasPermi('system:MhMessagesBoard:add')")
    @Log(title = "在线留言", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MhMessagesBoard mhMessagesBoard)
    {
        return toAjax(mhMessagesBoardService.insertMhMessagesBoard(mhMessagesBoard));
    }

    /**
     * 修改在线留言
     */
    @ApiOperation("修改在线留言")
    @PreAuthorize("@ss.hasPermi('system:MhMessagesBoard:edit')")
    @Log(title = "在线留言", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MhMessagesBoard mhMessagesBoard)
    {
        return toAjax(mhMessagesBoardService.updateMhMessagesBoard(mhMessagesBoard));
    }

    /**
     * 删除在线留言
     */
    @ApiOperation("删除在线留言")
    @PreAuthorize("@ss.hasPermi('system:MhMessagesBoard:remove')")
    @Log(title = "在线留言", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(mhMessagesBoardService.deleteMhMessagesBoardByIds(ids));
    }
    /**
     * 导入在线留言
     */
    @Log(title = "在线留言", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<MhMessagesBoard> util = new ExcelUtil<>(MhMessagesBoard.class);
        List<MhMessagesBoard> mhMessagesBoardList = util.importExcel(file.getInputStream());
        String operName = getUsername();
        String message = mhMessagesBoardService.imporIteminfo(mhMessagesBoardList, updateSupport, operName);
        return AjaxResult.success(message);
    }
    // 下载模板
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) throws IOException
    {
        ExcelUtil<MhMessagesBoard> util = new ExcelUtil<>(MhMessagesBoard.class);
        util.importTemplateExcel(response,"在线留言");
    }
}
